#!/usr/bin/env python2.5
# -*- coding: UTF-8 -*- 

from google.appengine.ext import db
from google.appengine.ext import deferred  
class MdlCache  (db.Model):
    val =db.BlobProperty    (indexed=False,  required=True,  verbose_name="Cache Vaue") 
    etag=db.StringProperty  (indexed=False,  required=True,  multiline=False, verbose_name="Cache Etag")
    @classmethod
    def get(cls, key):
        return cls.get_by_key_name(key, rpc= db.create_rpc(read_policy=db.EVENTUAL_CONSISTENCY))
    @classmethod
    def set(cls, key, val):
        if isinstance(val, unicode):val=val.encode('utf-8')
        return cls(key_name=key, val=val, etag=str(hash(val) ) ).put()
    @classmethod
    def setDeferred(cls, key, val):
        return deferred.defer(cls.set, key, val) 
